package com.api.smoke.action;

import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.request.model.ApiRequestBuilder;
import com.api.test.AbstractApiTest;
import com.api.test.VoidContextLoader;
import com.api.util.repo.DtoFactory;
import com.api.util.repo.impl.DomainUser;
import com.zyncro.api.IActionApiService;
import com.zyncro.api.IGroupApiService;
import com.zyncro.api.model.ObjectResultApi;

@ContextConfiguration(loader = VoidContextLoader.class)
public class GetActionsFromSecuenceSmoke extends AbstractApiTest {

	private String groupUrn;

	@BeforeClass
	protected void setUp() throws Exception {

		final String domainName = this.getClass().getSimpleName();
		final DomainUser mainAdmin = getRepo().getMainUser(domainName);

		getApi().login(mainAdmin.getAppId(), mainAdmin.getPassword());

		groupUrn = getRepo().getPropertyDto(domainName + "-GroupUrn", new DtoFactory<String>() {

			public String createDto() {

				try {
					ApiRequestBuilder request = getRequest(IGroupApiService.class, "createGroup");
					request.setParam("name", "name");

					ObjectResultApi<String> result = getApi().send(request);
					return result.getObject();

				} catch (Exception e) {

					throw new IllegalStateException("Exception creating test data", e);
				}
			}
		});
	}

	@Test
	public void testGetActionsFromSecuence() throws Exception {

		int pageSize = 10;

		ApiRequestBuilder request = getRequest(IActionApiService.class, "getActionsFromSequence");
		request.setParam("idgroup", groupUrn);
		request.setParam("pageSize", pageSize);
		getApi().send(request);
	}
}
